/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package fs.genomemap;

import genomemap.data.ChData;
import genomemap.data.Clone;
import genomemap.data.PDataSource;
import genomemap.data.Probe;

import javautil.collections.ArrayUtil;
import javautil.collections.RaggedArrayException;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author Susanta Tewari
 * @version 1.0
 * @created 09-Nov-2007 10:23:09 AM
 */
public class P_FileDataSource extends PDataSource {

    /**
     *
     * @param ch_id
     * @param order
     * @param pDataSettingsFile
     */
    public P_FileDataSource() {}

    /**
     * Constructs ...
     *
     * @param ch_id description
     * @param order description
     * @param chData description
     */
    public P_FileDataSource(int ch_id, int[] order, ChData chData) {

        setChId(ch_id);
        setOrder(order);
        setChData(chData);
    }

    @Override
    public void loadData() {

        try {

            String hybridFilePath = getChData().getHybridDataFilePath();

            setHybridData(ArrayUtil.get2DIntMArray(new File(hybridFilePath), false, ","));

        } catch (FileNotFoundException ex) {
            Logger.getLogger(P_FileDataSource.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RaggedArrayException ex) {
            Logger.getLogger(P_FileDataSource.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException | NumberFormatException ex) {
            Logger.getLogger(P_FileDataSource.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public LinkedHashSet<Probe> getFullProbeSet() {
        return new LinkedHashSet<>(FileSettings.load().getProbeSet(getChId()));
    }

    @Override
    public LinkedHashSet<Clone> getCloneSet() {
        return new LinkedHashSet<>(FileSettings.load().getCloneSet(getChId()));
    }
}
